$(function() {
	function suijishu() {
		//生成随机数
		var a = parseInt(Math.random() * 9 + 1).toString();
		var b = parseInt(Math.random() * 9 + 1).toString();
		var c = String.fromCharCode(Math.random() * 25 + 66);
		var d = String.fromCharCode(Math.random() * 25 + 98);
		var randomNum = a + b + c + d;
		console.log(randomNum);
		$('.imgRandom').append(randomNum);
	}
	suijishu();
	$('.imgRandom').click(function() {
		$('.imgRandom').html('');
		suijishu();
	})
	

	$('.dl').click(function() {
		//先拿到本地存储的值
		//将该值与用户输入夫人值进行对比  
		//若相等则跳转页面  若不想等则提示账号密码不正确
		var user = {
			tel: $('#username').val(),
			psw: $('#password').val()
		}
		console.log('user', user);
		var users = localStorage.getItem('users') ? JSON.parse(localStorage.getItem('users')) : [];
		// 1.先遍历本地存储的数组
		var telvalue = users.find(function(v, i) {
			console.log('v', v, 'index', i);
			return user.tel == v.tel && user.psw == v.psw;

		})
		console.log('telvalue', telvalue);
		if (telvalue) {
			window.location.href = "personal.html";
			localStorage.setItem(randomNum,"true");
		} else {
			alert('账号密码不正确!')
		}


	})
})
